package org.hismig.migration.result;
/**
 * @declare: //TODO <br />
 *           This class created by Vansion.Hopihit on 2012-07-04 <br />
 *           <a href="mailto:vansionhopihit@gmail.com">Contact Me</a>
 * @version 1.0
 * @author Vansion.Hopihit
 * 
 */
public class TableResultInfo extends BaseInfo {

	private ResultInfo sourcePreResultInfo;
	private ResultInfo distPreResultInfo;
	private ResultInfo executeResultInfo;
	private ResultInfo distAfterResultInfo;
	private ResultInfo sourceAfterResultInfo;

	public TableResultInfo(String name) {
		this.name = name;
	}

	public ResultInfo getSourcePreResultInfo() {
		return sourcePreResultInfo;
	}
	public void setSourcePreResultInfo(ResultInfo sourcePreResultInfo) {
		this.sourcePreResultInfo = sourcePreResultInfo;
	}
	public ResultInfo getDistPreResultInfo() {
		return distPreResultInfo;
	}
	public void setDistPreResultInfo(ResultInfo distPreResultInfo) {
		this.distPreResultInfo = distPreResultInfo;
	}
	public ResultInfo getExecuteResultInfo() {
		return executeResultInfo;
	}
	public void setExecuteResultInfo(ResultInfo executeResultInfo) {
		this.executeResultInfo = executeResultInfo;
	}
	public ResultInfo getDistAfterResultInfo() {
		return distAfterResultInfo;
	}
	public void setDistAfterResultInfo(ResultInfo distAfterResultInfo) {
		this.distAfterResultInfo = distAfterResultInfo;
	}
	public ResultInfo getSourceAfterResultInfo() {
		return sourceAfterResultInfo;
	}
	public void setSourceAfterResultInfo(ResultInfo sourceAfterResultInfo) {
		this.sourceAfterResultInfo = sourceAfterResultInfo;
	}

	@Override
	public int getErrorCount() {
		int count = super.getErrorCount();

		count += sourcePreResultInfo.getErrorCount();
		count += distPreResultInfo.getErrorCount();
		count += distAfterResultInfo.getErrorCount();
		count += sourceAfterResultInfo.getErrorCount();

		return count;
	}

	public String formate() {
		StringBuffer sb = new StringBuffer();
		sb.append("<html>");
		sb.append(String.format("<strong>表 : </strong>%s<p>", name));
		sb.append(String.format("<strong>耗时 : </strong>%sms<p>",
				getExecuteTime()));
		if (getErrorCount() > 0) {
			sb.append(String.format(
					"<strong><font color='red'>错误 : %s</font></strong><p>",
					getErrorCount()));
		} else {
			sb.append(String.format(
					"<strong><font color='green'>错误 : %s</font></strong><p>",
					getErrorCount()));
		}
		sb.append(String.format(
				"<strong>SourcePreExtExecutor : </strong>%s<p>",
				sourcePreResultInfo != null));
		sb.append(String.format("<strong>DistPreExtExecutor : </strong>%s<p>",
				distPreResultInfo != null));
		sb.append(String.format(
				"<strong>DistAfterExtExecutor : </strong>%s<p>",
				distAfterResultInfo != null));
		sb.append(String.format(
				"<strong>SourceAfterExtExecutor : </strong>%s<p>",
				sourceAfterResultInfo != null));

		sb.append("</html>");

		return sb.toString();
	}

	@Override
	public String toString() {
		return String.format("[数据表] - %s <耗时:%sms> (错误:%s)", new Object[]{name,
				getExecuteTime(), getErrorCount()});
	}
}
